import Vue from "vue";
import VueRouter from "vue-router";
import Laylout from '../views/Layout/index.vue'

Vue.use(VueRouter);

const routes = [
  {
    path: "/",
    redirect: "login",
    hidden: true,
    meta: {
      name: '主页'
    }
  },
  {
    path: "/login",
    name: "Login",
    hidden: true,
    meta: {
      name: '登录'
    },
    component: () => import("../views/Login/index.vue"),
  },
  {
    path: "/index",
    name: "index",
    meta: {
      name: '地图',
      icon: require('../assets/images/icon_dtms-2.png')
    },
    component: Laylout,
    children: [
      {
        path: "/index",
        name: "index",
        meta: {
          name: '地图'
        },
        component: () => import("../views/Map/index.vue"),
      }
    ]
  },
  {
    path: "/realTimeData",
    name: "realTimeData",
    meta: {
      name: '实时数据',
      icon: require('../assets/images/icon_sssj-2.png')
    },
    component: Laylout,
    children: [
      {
        path: "/realTimeData",
        name: "realTimeData",
        meta: {
          name: '实时数据'
        },
        component: () => import("../views/realTimeData/realTimeDataList.vue"),
      }
    ]
  },
  {
    path: "/callThePolice",
    name: "callThePolice",
    meta: {
      name: '报警记录',
      icon: require('../assets/images/icon_sssj-2.png')
    },
    component: Laylout,
    children: [
      {
        path: "/callThePolice",
        name: "callThePolice",
        meta: {
          name: '报警记录'
        },
        component: () => import("../views/callThePolice/callThePoliceList.vue"),
      }
    ]
  },
  {
    path: "/userManagement",
    name: "userManagement",
    meta: {
      name: '系统配置',
      icon: require('../assets/images/icon_sssj-2.png')
    },
    component: Laylout,
    children: [
      {
        path: "/userManagement",
        name: "userManagement",
        meta: {
          name: '用户管理'
        },
        component: () => import("../views/SystemSettings/userManagement.vue"),
      },
      {
        path: "/deviceManagement",
        name: "deviceManagement",
        meta: {
          name: '设备管理'
        },
        component: () => import("../views/SystemSettings/deviceManagement.vue"),
      },
      {
        path: "/threshold",
        name: "threshold",
        meta: {
          name: '阈值'
        },
        component: () => import("../views/SystemSettings/threshold.vue"),
      }
    ]
  },
];
//解决编程式路由往同一地址跳转时会报错的情况
const originalPush = VueRouter.prototype.push;
const originalReplace = VueRouter.prototype.replace;
//push
VueRouter.prototype.push = function push(location, onResolve, onReject) {
  if (onResolve || onReject)
    return originalPush.call(this, location, onResolve, onReject);
  return originalPush.call(this, location).catch(err => err);
};
//replace
VueRouter.prototype.replace = function push(location, onResolve, onReject) {
  if (onResolve || onReject)
    return originalReplace.call(this, location, onResolve, onReject);
  return originalReplace.call(this, location).catch(err => err);
};
const router = new VueRouter({
  mode: 'history',
  routes,
  base: 'ditto'
});

export default router;
